package com.wanxi.service.impl;

import com.wanxi.dao.ProductDao;
import com.wanxi.dao.impl.ProductDaoImpl;
import com.wanxi.dto.ResultDTO;
import com.wanxi.model.ProductModel;
import com.wanxi.service.ProductService;

import com.wanxi.util.JSONCopy;
import com.wanxi.vo.ProductVO;

public class ProductServiceImpl implements ProductService {
    private ProductDao productDao = new ProductDaoImpl();

    @Override
    public ResultDTO add(ProductVO productVO) {
        ProductModel model = JSONCopy.copy(productVO, ProductModel.class);

        return ResultDTO.getDTO(productDao.add(model), null);
    }

    @Override
    public ResultDTO update(ProductVO productVO) {
        ProductModel model = JSONCopy.copy(productVO, ProductModel.class);

        return ResultDTO.getDTO(productDao.update(model), null);
    }

    @Override
    public ResultDTO delete(ProductVO productVO) {
        ProductModel model = JSONCopy.copy(productVO, ProductModel.class);

        return ResultDTO.getDTO(productDao.delete(model), null);
    }

    @Override
    public ResultDTO findById(ProductVO productVO) {
        ProductModel model = JSONCopy.copy(productVO, ProductModel.class);

        return ResultDTO.getDTO(0, productDao.findById(model));
    }

    @Override
    public ResultDTO findAll(ProductVO productVO) {
        ProductModel model = JSONCopy.copy(productVO, ProductModel.class);

        return ResultDTO.getDTO(productDao.count(model), productDao.findAll(model));
    }

    @Override
    public ResultDTO count(ProductVO productVO) {
        ProductModel model = JSONCopy.copy(productVO, ProductModel.class);

        return ResultDTO.getDTO(productDao.count(model), null);
    }
}
